package com.echo.register.msm.receiver;

import com.alibaba.fastjson.JSONObject;
import com.echo.register.common.constant.MqConst;
import com.echo.register.msm.service.MsmService;
import com.echo.register.vo.msm.MsmVo;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName: HospitalReceiver
 * @Package: com.echo.register.hosp.receiver
 * @Description: 消息消费者
 * @Author 谢同学
 * @Create 2024/1/6 17:40
 * @Version 1.0
 */
@Component
@Slf4j
public class MsmReceiver {
    @Autowired
    private MsmService msmService;

    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(MqConst.EXCHANGE_DIRECT_MSM),// 交换机
            value = @Queue(name = MqConst.QUEUE_MSM_ITEM, durable = "true"),// 队列
            key = MqConst.ROUTING_MSM_ITEM) // 路由key
    ) // 消费消息
    public void receive(Message message, Channel channel, MsmVo msmVo) {
        System.out.println("1111");
        log.info("【医院服务-接收通知消息】：{}", JSONObject.toJSONString(msmVo));
        // 发送短信通知
        msmService.send(msmVo);
    }
}
